<template>
	<div class="aid">
		<div class="base">
			<p class="fixed-top">
				新增活动人员
				<a-icon @click="closeFunction" type="close" />
			</p>
			<div class="main">
				<a-form :form="form" :label-col="{ span: 5 }" :wrapper-col="{ span: 18 }" @submit="handleSubmit">
					<a-form-item label="活动人员">
						<a-select showSearch 
						optionFilterProp="children" style="width: 100%" 
						v-decorator="['UserNo', { rules: [{ required: true, message: '活动人员不能为空' }] }]"
						@search="fetchUser" :filterOption="filterOption">
							<a-spin v-if="fetching" slot="notFoundContent" size="small" />
							<a-select-option v-for="(item, index) in userList" :key="item.UserNo">{{ item.UserNo }}&nbsp;|&nbsp;{{ item.Name }}</a-select-option>
						</a-select>
					</a-form-item>
					<a-form-item label="类型">
						<a-radio-group v-decorator="['Type', { rules: [{ required: true, message: '请选择类型' }] }]" name="radioGroup">
							<a-radio v-for="(item, i) in ActivityMemberTypeList" :key="i" :value="item.Key">{{ item.Value }}</a-radio>
						</a-radio-group>
					</a-form-item>
					<a-form-item class="fixed-bottom" :wrapper-col="{ span: 12, offset: 5 }"><a-button type="primary" html-type="submit">提交</a-button></a-form-item>
				</a-form>
			</div>
		</div>
	</div>
</template>

<script>
import moment from 'moment';
import { DoAddActivityMember, GetUserList } from '@/api/follow';
const data = [];
export default {
	props: {
		text: Object,
		ActivityMemberTypeList:Array
	},
	data() {
		return {
			data,
			formLayout: 'horizontal',
			form: this.$form.createForm(this, {
				name: 'coordinated'
			}),
			fetching: false,
			userList: [],
		};
	},
	created() {
	},
	methods: {
		moment,
		filterOption(input, option) {
			return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0;
		},
		async fetchUser(value) {
			this.fetching = true;
			let myReg = /^[^a-zA-Z]+$/;
			if (value && value.length>1) {
				let data = {};
				data.key = value;
				data.top = 20;
				let res = await GetUserList(data);
				this.fetching = false;
				this.userList = res.data.data;
			}
		},
		closeFunction(data) {
			this.form.resetFields();
			this.$emit('closeFun', data);
		},
		handleSubmit(e) {
			e.preventDefault();
			this.form.validateFields(async (err, values) => {
				if (!err) {
					let data={}
					data = values
					data.ActivityID = this.text.ActivityID
					let res = await DoAddActivityMember(data);
					this.$message.success(res.data.msg)
					if(res.data.code==0){
						this.closeFunction(1)
					}
				}
			});
		}
	}
};
</script>

<style lang="less" scoped>
.aid {
	position: fixed;
	width: 100%;
	height: 100%;
	background: rgba(0, 0, 0, 0.5);
	top: 0px;
	left: 0px;
	z-index: 999;
}

.base {
	position: absolute;
	width: 600px;
	height: 540px;
	background: #fff;
	left: 50%;
	margin-left: -300px;
	top: 50%;
	margin-top: -270px;
	overflow-y: auto;
}
.main {
	height: 90%;
	overflow-y: scroll;
}
/deep/.ant-form-item {
	margin: 20px 50px;
}
/deep/.ant-form-item-label {
	width: 100px !important;
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
	text-align: right;
}
/deep/.ant-form-item-control-wrapper {
	flex: 1;
}
/deep/.ant-calendar-picker,
/deep/.ant-time-picker {
	width: 100%!important;
}
.fixed-top {
	width: inherit;
	position: absolute;
	line-height: 30px;
	top: 0px;
	background-color: white;
	z-index: 999;
	padding: 10px 0 0 10px;
}
.fixed-bottom {
	width: 164px;
	left: 50%;
	bottom: 0px;
	margin: 0px 0px 0px -82px !important;
	position: absolute;
	background-color: white;
	z-index: 999;
}
/deep/.ant-form {
	margin-top: 50px;
	padding-bottom: 50px;
}
</style>
